//
//  HomeTableViewController.swift
//  WeiBoSwift
//
//  Created by admin on 2017/11/21.
//  Copyright © 2017年 admin. All rights reserved.
//

import UIKit

class HomeTableViewController: BaseTableViewController {
    
    //MARK:- 声明属性
    lazy var popViewAnimator : PopViewAnimator = PopViewAnimator()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 没有登录 return
        if !isLogin {
            return
        }
        
        // 登陆之后
        setupLoginNavigationItem()
    }
    
    /// 登录之后的navigationItem
    private func setupLoginNavigationItem() {
        // leftBarButtonItem
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(imageName: "navigationbar_friendattention")
        
        // rightBarButtonItem
        navigationItem.rightBarButtonItem = UIBarButtonItem.init(imageName: "navigationbar_pop")
        
        // titleView
        let titleButton : TitleButton = TitleButton()
        titleButton.setTitle("老虎棒子鸡", for: .normal)
        titleButton.addTarget(self, action: #selector(titleButtonClick), for: .touchUpInside)
        navigationItem.titleView = titleButton
    }
    
    /// titleButton的点击事件
    @objc private func titleButtonClick (sender : TitleButton) {
        sender.isSelected = !sender.isSelected
        
        let popVC : PopAlertViewController = PopAlertViewController()
        // present出vc后使上一个vc的控件不隐藏
        popVC.modalPresentationStyle = .custom
        popVC.transitioningDelegate = popViewAnimator
        popViewAnimator.presentedFrame = CGRect.init(x: (kScreenWidth - 150) / 2, y: 50, width: 150, height: 200)
        print(popViewAnimator.isPresented)
        present(popVC, animated: true, completion: nil)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

